<template>
  <div id="experimentData">
    <el-card class="box-card" style="margin:15px">
      <el-form ref="basicForm" :inline="true" :model="basicData" size="small" label-width="100px">
        <el-row>
          <el-col :span="5">
            <el-form-item label="实验项目:">
              <el-select
                size="mini"
                v-model="basicData.experimentCode.key"
                placeholder="选择"
                @change="selectPojeck"
              >
                <el-option
                  v-for="(item, key, index) in dicts.EXPERIMENT_CODE"
                  :key="index"
                  :label="item"
                  :value="key"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="实验批次:">
              <el-select size="mini" v-model="basicData.experimentSwatchId" placeholder="选择">
                <el-option
                  v-for="(item, key, index) in basicSwatchList"
                  :key="index"
                  :label="item.batchNumber"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="14">
            <el-col :span="14">
              <el-form-item label="实验日期:">
                <el-date-picker
                  size="mini"
                  v-model="dateList"
                  style="width:100%"
                  type="daterange"
                  range-separator="至"
                  value-format="yyyy-MM-dd"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  @change="timeChange"
                />
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item label="布板序号:">
                <div style="display:flex;align-items: center;">
                  <el-form-item>
                    <el-input
                      size="mini"
                      v-model="basicData.seq.start"
                      placeholder="输入"
                      style="width:65px"
                      onkeyup="this.value=this.value.replace(/\D|^0/g,'')"
                      onafterpaste="this.value=this.value.replace(/\D|^0/g,'')"
                    />
                  </el-form-item>
                  <span style="margin: 0 10px">至</span>
                  <el-form-item>
                    <el-input
                      size="mini"
                      v-model="basicData.seq.end"
                      placeholder="输入"
                      style="width:65px"
                      onkeyup="this.value=this.value.replace(/\D|^0/g,'')"
                      onafterpaste="this.value=this.value.replace(/\D|^0/g,'')"
                    />
                  </el-form-item>
                </div>
              </el-form-item>
            </el-col>
          </el-col>
        </el-row>
        <div style="display:flex;width:100%;justify-content: center;margin-top:20px">
          <el-button
            type="primary"
            size="mini"
            style="width:120px"
            icon="el-icon-document-checked"
            @click="getList(basicData)"
          >查询</el-button>
        </div>
      </el-form>
    </el-card>
    <el-card class="box-card" style="margin:15px">
      <div style="margin-bottom:10px">
        <el-button size="small" type="primary" icon="el-icon-upload2" @click="clickSetSync">同步</el-button>
        <el-button size="small" type="primary" @click="clickSwatch">布板</el-button>
        <el-button size="small" type="primary" @click="clickMerge">合并结果</el-button>
      </div>
      <el-table
        v-loading="loading"
        :data="tableData"
        style="width: 100%;padding:5px;"
        :header-cell-style="{
          background: '#333333',
          color: '#ffffff',
          textAlign: 'center'
        }"
        class="table-date"
        @selection-change="selectChanage"
      >
        <el-table-column align="center" type="selection" width="55" />
        <el-table-column align="center" prop="expNum" label="实验编号" width="155" />
        <el-table-column align="center" prop="barCode" label="条码" width="155" />
        <el-table-column align="center" prop="posNumber" label="孔号" width="155" />
        <el-table-column align="center" prop="keyNumber" label="布板位置" width="155" />
        <el-table-column align="center" prop="seq" label="实验序号" />
        <el-table-column align="center" prop="experimentDate" label="实验日期">
          <template slot-scope="scope">
            <span>
              {{
              scope.row.experimentDate
              ? scope.row.experimentDate.substr(0, 10)
              : ""
              }}
            </span>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="experimentValue" label="实验值">
          <template slot-scope="scope">
            <span>{{scope.row.simpleResult.substr(0,20)}}…</span>
            <span
              style="color: #1890ff;cursor: pointer;"
              @click="clickSeeExpValue(scope.row.experimentValue)"
            >点击查看</span>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="seq" label="合并状态">
          <template slot-scope="scope">
            <span
              :style="scope.row.sampleBloodId == 0 ?'color:#f8771f':'color:green'"
            >{{scope.row.sampleBloodId == 0 ? '未合并' :'已合并'}}</span>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="basicData.current"
        :page-size="basicData.size"
        :total="total"
        layout="slot, total, sizes, prev, pager, next, jumper"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      >
        <span
          v-if="selectList.length > 0"
          style="font-weight: 400;color:#606266"
        >已选中{{ selectList.length }}条，</span>
      </el-pagination>
    </el-card>

    <!-- 同步 -->
    <el-dialog
      width="65%"
      :close-on-press-escape="false"
      :close-on-click-modal="false"
      title="同步数据"
      :visible.sync="SyncShow"
      append-to-body
    >
      <el-form ref="projectManageForm" :model="syncData" label-width="120px" size="small">
        <el-row>
          <el-col :span="24">
            <el-form-item label="实验项目：">
              <el-radio-group v-model="syncData.code" border="true" size="small">
                <el-radio
                  v-for="(item, key, index) in dicts.EXPERIMENT_CODE"
                  :key="index"
                  :label="key"
                  :value="key"
                >{{ item }}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="实验日期：">
              <el-date-picker
                size="mini"
                v-model="syncData.date"
                type="date"
                value-format="yyyy-MM-dd"
              />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <div style="display:flex;widht:100%;justify-content: center;">
              <el-button size="small" type="primary" @click="clickSync" v-loading="syncloading">同步</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>

    <!-- 布板 -->
    <el-dialog
      width="85%"
      append-to-body
      id="experimentData-dialog"
      :close-on-press-escape="false"
      :close-on-click-modal="false"
      title="布板"
      :visible.sync="swatchShow"
    >
      <el-form
        ref="basicForm"
        :rules="swatchDataFormRules"
        :inline="true"
        :model="swatchData"
        class="demo-form-inline"
        size="small"
        label-width="100px"
        v-loading="swatchLoading"
      >
        <el-row>
          <el-col :span="6">
            <el-form-item label="实验批号:" prop="batchNumber">
              <el-input size="mini" disabled v-model="swatchData.batchNumber" placeholder="输入" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="布板方案:" prop="swatchId.key">
              <el-select size="mini" disabled v-model="swatchData.swatchId.key" placeholder="选择">
                <el-option
                  v-for="(item, index) in swatchList"
                  :key="index"
                  :label="item.swatchName"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="布板人员:" prop="swatchMan">
              <el-input size="mini" disabled v-model="swatchData.swatchMan" placeholder="输入" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="布板日期:" prop="swatchTime">
              <el-date-picker
                size="mini"
                disabled
                v-model="swatchData.swatchTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择日期"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="试剂1:" prop="reagent1.key">
              <el-select size="mini" disabled v-model="swatchData.reagent1.key" placeholder="选择">
                <el-option
                  v-for="(item, index) in queryReagentList"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="试剂2:">
              <el-select size="mini" disabled v-model="swatchData.reagent2.key" placeholder="选择">
                <el-option
                  v-for="(item, index) in queryReagentList"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="质控品:" prop="qualityControl.key">
              <el-select
                size="mini"
                disabled
                v-model="swatchData.qualityControl.key"
                placeholder="选择"
              >
                <el-option
                  v-for="(item, index) in queryQualityList"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="选中位置:">
              <el-input size="mini" disabled v-model="banItem.selectW" placeholder="输入" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="条形码号:">
              <el-input size="mini" disabled v-model="banItem.barcode" placeholder="输入" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="起始编号:">
              <el-input size="mini" disabled v-model="banItem.startCode" placeholder="输入" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="终止编号:">
              <el-input size="mini" disabled v-model="banItem.endCode" placeholder="输入" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="选中条码:">
              <el-input size="mini" disabled v-model="banItem.selectCode" placeholder="输入" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <div style="display: flex;justify-content: center;margin:10px 0">
              <el-button type="primary" size="mini" @click="clickSet">设置</el-button>
              <!-- <el-button size="mini">复制</el-button> -->
              <el-button type="primary" size="mini" @click="clickSeave">保存</el-button>
            </div>
          </el-col>

          <!-- 表格 -->
          <el-col :span="10">
            <div id="ban-table-tow">
              <el-table
                v-loading="loading"
                :data="queryRecheckData"
                style="width: 100%;padding:5px;"
                :header-cell-style="{
                  background: '#333333',
                  color: '#ffffff',
                  textAlign: 'center'
                }"
                @row-dblclick="clickRowDB"
              >
                <el-table-column align="center" type="index" width="55" />
                <el-table-column align="center" prop="expNum" label="实验编号" width="150" />
                <el-table-column align="center" prop="bloodProperty.data" label="样本属性" />
                <el-table-column align="center" prop="barCode" label="条形码号" width="150" />
                <el-table-column align="center" prop="bloodNum" label="采血编号" width="150" />
                <el-table-column align="center" prop="bloodReview.data" label="原血复查">
                  <template slot-scope="scope">
                    <span
                      :style="
                        scope.row.bloodReview.data == '是' ? 'color:red' : ''
                      "
                    >{{ scope.row.bloodReview.data }}</span>
                  </template>
                </el-table-column>
              </el-table>
            </div>
            <div id="ban-table-tow">
              <el-table
                v-loading="importLoading"
                :data="queryNormalData"
                style="width: 100%;padding:5px;"
                :header-cell-style="{
                  background: '#333333',
                  color: '#ffffff',
                  textAlign: 'center'
                }"
                @row-dblclick="clickRowDB"
              >
                <el-table-column align="center" type="index" width="55" />
                <el-table-column align="center" prop="expNum" label="实验编号" width="150" />
                <el-table-column align="center" prop="bloodProperty.data" label="样本属性" />
                <el-table-column align="center" prop="barCode" label="条形码号" width="150" />
                <el-table-column align="center" prop="bloodNum" label="采血编号" width="150" />
                <!-- <el-table-column align="center" prop=" " label="" /> -->
                <el-table-column align="center">
                  <template slot="header" slot-scope="scope">
                    <el-upload
                      ref="upload"
                      action
                      :http-request="requestUpload"
                      :on-change="onChange"
                      :show-file-list="false"
                      :accept="'.xls, .xlsx'"
                      style="display: flex;align-items: center;justify-content: center;padding: 0;"
                    >
                      <el-button
                        size="small"
                        type="primary"
                        style="display: flex;align-items: center;justify-content: center;padding: 5px;"
                      >导入数据</el-button>
                    </el-upload>
                  </template>
                  <template slot-scope="scope"></template>
                </el-table-column>
              </el-table>
            </div>
          </el-col>
          <!-- 布板 -->
          <el-col :span="14">
            <buBan
              v-if="banShow"
              @chanageDataList="chanageDataList"
              @selectRow="selectRow"
              ref="buBanRef"
              :banTotal="banTotal"
              :dataList="banData"
              :codeList="codeList"
              :rowList="columnList"
              :columnList="rowList"
            ></buBan>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>

    <!-- 点击查看 -->
    <el-dialog
      width="65%"
      :close-on-press-escape="false"
      :close-on-click-modal="false"
      title="实验值"
      :visible.sync="seeShow"
      append-to-body
    >
      <!-- 表格 -->
      <el-row style="line-height: 1.5;border:1px solid">
        <el-col
          :span="5"
          style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;border-right:1px solid"
        >筛查项目</el-col>
        <el-col
          :span="3"
          style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;border-right:1px solid"
        >检测指标</el-col>
        <el-col
          :span="3"
          style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;border-right:1px solid"
        >检测值</el-col>
        <el-col
          :span="5"
          style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;border-right:1px solid"
        >正常参考值</el-col>
        <el-col
          :span="8"
          style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;"
        >筛查结果</el-col>
        <!-- hint -->
      </el-row>
      <!-- 表格内容 -->
      <el-row
        style="line-height: 1.5;border-bottom:1px solid;border-left:1px solid;border-right:1px solid;"
      >
        <div v-for="(item, index) in seeData" :key="index">
          <el-col
            :span="5"
            :style="item.experimentValueResult != 'normal' ? 'background-color:#baccef;':''"
            style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;border-right:1px solid"
          >{{ item.indicatorCodeName }}&nbsp</el-col>
          <el-col
            :span="3"
            :style="item.experimentValueResult != 'normal' ? 'background-color:#baccef;':''"
            style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;border-right:1px solid"
          >{{ item.indicatorCode }}&nbsp</el-col>
          <el-col
            :span="3"
            :style="item.experimentValueResult != 'normal' ? 'background-color:#baccef;':''"
            style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;border-right:1px solid"
          >{{ item.experimentValue }}{{ item.units }}&nbsp</el-col>
          <el-col
            :span="5"
            :style="item.experimentValueResult != 'normal' ? 'background-color:#baccef;':''"
            style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;border-right:1px solid"
          >{{ item.referenceValue }}&nbsp</el-col>
          <el-col
            :span="8"
            :style="item.experimentValueResult != 'normal' ? 'background-color:#baccef;':''"
            style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;border-right:1px solid"
          >{{ item.hint }}&nbsp</el-col>
        </div>
      </el-row>
    </el-dialog>
  </div>
</template>

<script>
import DeliveryManageApi from "@/api/DeliveryManage.js";
import { initDicts } from "@/utils/commons";
import QualityManageApi from "@/api/QualityManage.js";
import ConsumableManageApi from "@/api/ConsumableManage.js";
import userApi from "@/api/User.js";
import buBan from "@/components/ban/buBan";
import importSampleApi from "@/api/importSample.js";

export default {
  components: {
    buBan
  },
  data() {
    return {
      loading: false,
      // 弹窗转菊花
      swatchLoading: false,
      // 布板弹窗
      swatchShow: false,
      // 布板显示
      banShow: false,
      // 合并结果
      mergeShow: false,
      //转菊花
      loading: false,
      // 同步数据
      SyncShow: false,
      // 点击同步转菊花
      syncloading: false,
      // 点击查看
      seeShow: false,
      // 点击查看数据
      seeData: {},
      // 布板数据
      banData: [],
      // 布板列数
      rowList: [],
      // 布板行数
      columnList: [],
      // 板数量
      banTotal: 0,
      // 布板数据
      swatchData: {
        batchNumber: "",
        experimentCode: {
          key: ""
        },
        qualityControl: {
          key: ""
        },
        reagent1: {
          key: ""
        },
        reagent2: {
          key: ""
        },
        swatchId: {
          key: ""
        },
        swatchMan: this.$store.state.account.user.name,
        swatchTime: "",
        swatchValue: []
      },
      // 板本地操作数据
      banItem: {
        selectW: "",
        barcode: "",
        startCode: "",
        endCode: "",
        selectCode: ""
      },
      // 复检样本
      queryRecheckData: [],
      // 正常样本
      queryNormalData: [],
      // 复检样本转菊花
      queryRechecLoading: false,
      // 正常样本转菊花
      queryNormalLoading: false,
      // 正常样本表格转菊花
      importLoading: false,
      // 选中的编码
      codeList: [],
      // 试剂
      queryReagentList: [],
      // 质控品
      queryQualityList: [],
      inExpData: {
        bloodArea: "",
        deliveryDepart: "",
        deliveryId: "",
        deliveryMan: this.$store.state.account.user.name,
        deliveryTime: ""
      },
      // 文件
      file: {},
      // 布板校验
      swatchDataFormRules: {
        batchNumber: [{ required: true, message: "   ", trigger: "change" }],
        "swatchId.key": [{ required: true, message: "   ", trigger: "change" }],
        swatchMan: [{ required: true, message: "   ", trigger: "change" }],
        swatchTime: [{ required: true, message: "   ", trigger: "change" }],
        "reagent1.key": [{ required: true, message: "   ", trigger: "change" }],
        "qualityControl.key": [
          { required: true, message: "   ", trigger: "change" }
        ]
      },

      // 同步数据表单
      syncData: {
        code: "",
        date: ""
      },
      // 表格数据
      tableData: [],
      // 选中数据
      selectList: [],
      // 查询数据
      basicData: {
        experimentCode: {
          data: "",
          key: ""
        },
        experimentDate: {
          end: "",
          start: ""
        },
        experimentSwatchId: "",
        seq: {
          end: "",
          start: ""
        }
      },
      // 总数
      total: 0,
      // 字典
      dicts: {
        EXPERIMENT_CODE: {} //实验项目
      },
      // 实验批次
      basicSwatchList: [],
      // 实验批次
      swatchList: [],
      // 实验日期列表
      dateList: []
    };
  },
  mounted() {
    initDicts(["EXPERIMENT_CODE"], this.dicts);
    // this.getList(this.basicData);
    let userdata = {
      size: 9999,
      current: 1,
      sort: "id",
      order: "descending",
      model: {
        nation: { key: "" },
        education: { key: "" },
        positionStatus: { key: "" },
        org: { key: null },
        station: { key: null },
        sex: { code: "" }
      },
      map: {},
      timeRange: null
    };
    userApi.page(userdata).then(response => {
      const res = response.data;
      if (res.isSuccess) {
        res.data.records.forEach(item => {
          if (item.id == this.$store.state.account.user.id) {
            this.inExpData.deliveryDepart = item.name;
            this.inExpData.bloodArea = item.name;
          }
        });
      }
    });
  },
  methods: {
    // 过滤去重(获取布板列数)
    filRowList(arr) {
      let data = [];
      arr.forEach(item => {
        data.push(item.r);
      });
      return Array.from(new Set(data));
    },
    // 过滤去重(获取布板列数)
    filColumnList(arr) {
      let data = [];
      arr.forEach(item => {
        data.push(
          this.direction.key == "horizontal" ? item.r : item.pos.split("-")[1]
        );
      });
      return Array.from(new Set(data));
    },
    // 获取当前点击行
    selectRow(v) {
      this.clickRow = v;
      this.banItem.selectW = v.pos;
    },
    // 布板内数据变化
    chanageDataList(v) {
      this.swatchData.swatchValue = v;
    },
    // 上传文件
    onChange(file) {
      this.file = file.raw;
    },
    // 修改上传文件地址
    requestUpload(file) {
      let that = this;
      //  表单提交方式
      let FormDatas = new FormData();
      this.importLoading = true;
      FormDatas.append("file", that.file);
      importSampleApi.applayList
        .importFile(FormDatas)
        .then(function(res) {
          if (res.data.isSuccess) {
            res.data.data.forEach(item => {
              that.queryNormalData.push(item);
            });
          } else {
            that.$message.error(res.data.data.msg);
          }
        })
        .finally(() => (this.importLoading = false));
    },
    // 保存
    clickSeave() {
      this.$refs["basicForm"].validate(valid => {
        if (valid) {
          DeliveryManageApi.addSample.putData(this.swatchData).then(res => {
            if (res.status === 200) {
              this.$message({
                type: "success",
                message: res.statusText
              });
              this.swatchShow = false;
              this.resultData();
            } else {
              this.$message.error(res.statusText);
            }
          });
        } else {
          return false;
        }
      });
    },
    // 点击当前行设置布板内部数据
    clickRowDB(v) {
      let list = this.banData;
      let arr = list.map(item => item.s);
      this.codeList = [];
      if (arr.indexOf(v.expNum) > -1) {
        this.$message.error("此条形码号样本已经布板");
      } else {
        this.codeList.push(v.expNum);
      }
      if (this.codeList.length > 0) {
        setTimeout(() => {
          this.$refs.buBanRef.setCode();
        }, 300);
      }
    },
    // 点击布板
    clickSwatch() {
      if (this.basicData.experimentSwatchId) {
        this.swatchShow = true;
        this.swatchLoading = true;
        this.swatchData.swatchTime =
          new Date().getFullYear().toString() +
          "-" +
          ((new Date().getMonth() + 1).toString() < 10
            ? "0" + (new Date().getMonth() + 1).toString()
            : (new Date().getMonth() + 1).toString()) +
          "-" +
          (new Date().getDate().toString() < 10
            ? "0" + new Date().getDate().toString()
            : new Date().getDate().toString());
        // 查询已存复检
        DeliveryManageApi.experimentData
          .querySavedRecheck({
            experimentSwatchId: this.basicData.experimentSwatchId
          })
          .then(res => {
            this.queryRecheckData = res.data.data;
          });
        // 查询已存初验
        DeliveryManageApi.experimentData
          .querySavedNormal({
            experimentSwatchId: this.basicData.experimentSwatchId
          })
          .then(res => {
            this.queryNormalData = res.data.data;
          });
        // 查询已存布板
        DeliveryManageApi.experimentData
          .querySavedSwatch({
            experimentSwatchId: this.basicData.experimentSwatchId
          })
          .then(res => {
            this.swatchData = res.data.data;
            this.banData = res.data.data.swatchValue;
            this.banTotal = 0;
            res.data.data.swatchValue.forEach(item => {
              if (item.ban > this.banTotal) {
                this.banTotal++;
              }
            });
            this.columnList = [];
            this.rowList = [];
            this.filRowList(res.data.data.swatchValue).forEach(
              (item, index) => {
                this.rowList[index] = {
                  id: item,
                  type: ""
                };
              }
            );
            if (this.rowList[0].type != "banIndex") {
              this.rowList.unshift({ id: "1", type: "banIndex" });
            }
            this.columnList = this.filColumnList(res.data.data.swatchValue); //根据布板数组过滤行数
            this.banShow = true;
            // 重置布板数据
            setTimeout(() => {
              this.$refs.buBanRef.getList();
            }, 200);

            // 方案名称
            let swatchSchemeManage = {
              current: 1,
              map: {},
              model: {
                experimentCode: {
                  data: "",
                  key: this.swatchData.experimentCode.key
                },
                swatchName: ""
              },
              order: "descending",
              size: 10,
              sort: "id"
            };
            QualityManageApi.swatchSchemeManage
              .page(swatchSchemeManage)
              .then(res => {
                this.swatchList = res.data.data.records;
              });

            // 试剂名称
            ConsumableManageApi.reagentManage
              .queryReagent({ code: this.swatchData.experimentCode.key })
              .then(res => {
                this.queryReagentList = res.data.data;
              });
            // 质控品
            ConsumableManageApi.reagentManage
              .queryQuality({ code: this.swatchData.experimentCode.key })
              .then(res => {
                this.queryQualityList = res.data.data;
              });
          });

        this.inExpData.deliveryId =
          new Date().getFullYear().toString() +
          ((new Date().getMonth() + 1).toString() < 10
            ? "0" + (new Date().getMonth() + 1).toString()
            : (new Date().getMonth() + 1).toString()) +
          (new Date().getDate().toString() < 10
            ? "0" + new Date().getDate().toString()
            : new Date().getDate().toString()) +
          new Date().getHours().toString() +
          new Date().getMinutes().toString() +
          new Date().getSeconds().toString();
        this.inExpData.deliveryTime =
          new Date().getFullYear().toString() +
          "-" +
          ((new Date().getMonth() + 1).toString() < 10
            ? "0" + (new Date().getMonth() + 1).toString()
            : (new Date().getMonth() + 1).toString()) +
          "-" +
          (new Date().getDate().toString() < 10
            ? "0" + new Date().getDate().toString()
            : new Date().getDate().toString());

        DeliveryManageApi.acceptanceTesting
          .inExpress(this.inExpData)
          .then(res => {});
        setTimeout(() => {
          this.swatchLoading = false;
        }, 300);
      } else {
        this.$message.error("请选择实验批次！");
      }
    },
    // 点击设置
    clickSet() {
      if (this.swatchData.swatchId.key == "") {
        this.$message.error("请选择布板方案");
      } else if (this.banItem.selectW == "") {
        this.$message.error("请选择起始位置");
      } else if (
        (this.banItem.startCode != "" && this.banItem.endCode == "") ||
        (this.banItem.startCode == "" && this.banItem.endCode != "")
      ) {
        this.$message.error("编号无数字部分");
      } else if (this.banItem.startCode > this.banItem.endCode) {
        this.$message.error("起始编号不能大于终止编号");
      } else if (this.banItem.endCode - this.banItem.startCode > 2000) {
        this.$message.error("编号区间跨度过大");
      } else if (this.banItem.startCode != "" && this.banItem.endCode != "") {
        let unList = []; //缺少的样本
        this.codeList = [];
        let codeList = [];
        this.queryNormalData.forEach((item, index) => {
          if (
            item.expNum > this.banItem.startCode &&
            item.expNum < this.banItem.endCode
          ) {
            codeList.push(item.expNum);
          }
        });

        for (
          let index = this.banItem.startCode;
          index < Number(this.banItem.endCode) + 1;
          index++
        ) {
          codeList.forEach(item => {
            if (item != index) {
              unList.push(item);
            }
          });
        }
        this.$confirm(
          `缺少以下可布板样本：<div style="width: 280px;overflow: hidden;white-space: normal;word-break: break-all;max-height:360px;overflow: auto;">${unList.toString()}</div>，是否对可布板样本进行布板？`,
          "提示",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            dangerouslyUseHTMLString: true,
            type: "warning"
          }
        ).then(() => {
          this.codeList = codeList;
          if (this.codeList.length > 0) {
            setTimeout(() => {
              this.$refs.buBanRef.setCode();
            }, 300);
          }
        });
      } else {
        let list = this.banData;
        let arr = list.map(item => item.s);
        this.codeList = [];
        this.queryNormalData.forEach((item, index) => {
          if (arr.indexOf(item.expNum) > -1) {
          } else {
            this.codeList.push(item.expNum);
          }
        });
        if (this.codeList.length > 0) {
          setTimeout(() => {
            this.$refs.buBanRef.setCode();
          }, 300);
        }
      }
    },
    // 合并结果
    clickMerge() {
      if (this.selectList.length == 0) {
        this.$message.error("请选择要合并的数据！");
        return;
      }
      DeliveryManageApi.experimentData
        .mergeResult(this.selectList)
        .then(res => {
          if (res.status === 200) {
            this.$message({
              type: "success",
              message: res.statusText
            });
            this.getList(this.basicData);
          } else {
            this.$message.error(res.statusText);
          }
          console.log(res.data);
        });
    },
    // 点击查看
    clickSeeExpValue(v) {
      this.seeShow = true;
      let sortData = [];
      for (let key in v) {
        sortData.push(v[key]);
      }
      this.seeData = this.$keysrt(sortData, "sortValue");
    },
    // 选择实验项目
    selectPojeck(v) {
      this.basicSwatchList = [];
      this.basicData.experimentSwatchId = "";
      DeliveryManageApi.experimentData
        .queryExperimentSwatch({ code: v })
        .then(res => {
          this.basicSwatchList = res.data.data;
        });
    },
    // 实验日期变动时候调用
    timeChange(v) {
      if (v && v.length > 0) {
        this.basicData.experimentDate.start = v[0];
        this.basicData.experimentDate.end = v[1];
      } else {
        this.basicData.experimentDate = {
          end: "",
          start: ""
        };
      }
    },
    // 点击同步数据按钮
    clickSetSync() {
      this.SyncShow = true;
    },
    // 点击同步
    clickSync() {
      this.syncloading = true;
      if (this.syncData.code == "") {
        this.$message.error("请选择项目");
        return;
      }
      if (this.syncData.date == "") {
        this.$message.error("请选择日期");
        return;
      }
      DeliveryManageApi.experimentData.sync(this.syncData).then(res => {
        if (res.status == 200) {
          setTimeout(() => {
            this.getList(this.basicData);
            this.syncloading = false;
            this.SyncShow = false;
          }, 2000);
        } else {
          this.$message.error(res.statusText);
        }
      });
    },
    // 获取数据
    getList(data) {
      this.loading = true;
      DeliveryManageApi.experimentData
        .page(data)
        .then(res => {
          if (res.status === 200) {
            this.tableData = res.data.data;
          } else {
            this.$message.error(res.statusText);
          }
        })
        .finally(() => (this.loading = false));
      let userdata = {
        size: 9999,
        current: 1,
        sort: "id",
        order: "descending",
        model: {
          nation: { key: "" },
          education: { key: "" },
          positionStatus: { key: "" },
          org: { key: null },
          station: { key: null },
          sex: { code: "" }
        },
        map: {},
        timeRange: null
      };
      userApi.page(userdata).then(response => {
        const res = response.data;
        if (res.isSuccess) {
          res.data.records.forEach(item => {
            if (item.id == this.$store.state.account.user.id) {
              this.inExpData.deliveryDepart = item.org.data.label;
              this.inExpData.bloodArea = item.org.data.label;
            }
          });
        }
      });
    },
    //点击全选
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    // 点击分页
    handleSizeChange: function(val) {
      this.basicData.size = val;
      this.getList(this.basicData);
    },
    // 选择页码
    handleCurrentChange: function(currentPage) {
      this.basicData.current = currentPage;
      this.getList(this.basicData);
    },
    // 选中数据操作
    selectChanage(v) {
      this.selectList = v;
    }
  }
};
</script>

<style lang="less">
#experimentData {
  .table-date {
    .el-table_1_column_5 {
      border-right: 1px solid;
    }
  }
}
#experimentData-dialog {
  display: flex;
  justify-content: center;
  align-items: center;
  .el-dialog {
    margin-top: 0 !important;
  }
  .el-message-box__message {
    width: 280px;
    overflow: hidden;
    white-space: normal;
    word-break: break-all;
  }
  #ban-table-tow {
    .el-table__body-wrapper {
      height: 200px !important;
      overflow-y: auto;
    }
  }
  .el-dialog__title {
    color: #fff;
  }
  .el-form-item__content {
    width: 80%;
    .el-select {
      width: 100%;
    }
    .el-date-editor {
      width: 100%;
    }
  }
}
</style>
